package com.yc.mvc;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class MvcConfig extends WebMvcConfigurationSupport {

    // 文件上传解析器 (解析 http 报文)
    @Bean("multipartResolver")
    public MultipartResolver getCMR() {
        CommonsMultipartResolver cmr = new CommonsMultipartResolver();
        // 单个文件上传大小
        cmr.setMaxUploadSizePerFile(1024 * 1024 * 2);
        // 总大小
        cmr.setMaxUploadSize(1024 * 1024 * 10);
        return cmr;
    }

    // 添加 静态资源映射 配置方法
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("----------------------------");
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:/D:/_文件柜/97/upload/");
    }
}
